package com.zpphis.controller;

import com.zpphis.entity.Menu;
import com.zpphis.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @RequestMapping("/table.json")
    public Map<String, Object> table() {

        return new HashMap<String, Object>() {
            {
                put("code", 0);
                put("data", menuService.list());
            }
        };

    }

    @RequestMapping("/queryOne.json")
    public Menu queryOne(int id) {
        return menuService.getById(id);
    }

    @RequestMapping("/edit.json")
    public Map<String, Object> edit(Menu menu) {
        if (menuService.updateById(menu)) {
            return new HashMap<String, Object>() {
                {
                    put("code", 1);
                }
            };
        } else {
            return new HashMap<String, Object>() {
                {
                    put("code", 0);
                    put("msg", "修改失败！");
                }
            };
        }
    }
}
